package com.yyjj.zixun.fragmnet;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.aries.ui.view.title.TitleBarView;
import com.yyjj.zixun.R;
import com.yyjj.zixun.adapter.viewpager.VPTitleAdapter;
import com.zhengsr.viewpagerlib.indicator.TabIndicator;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import tech.com.commoncore.base.BaseFragment;
import tech.com.commoncore.base.BaseTitleFragment;
import tech.com.commoncore.basecomponent.ServiceFactory;

/**
 * Anthor:NiceWind
 * Time:2019/3/25
 * Desc:The ladder is real, only the climb is all.
 */
public class ZXFragment extends BaseTitleFragment {
    private TabIndicator mLineIndicator;
    private ViewPager mViewpager;

//    public static final String[] TYPES = {"自选","bituan", "bitmex", "huobipro", "cointiger", "okex"};
    public static final String[] TYPES = {"头条","快讯"};
    List<Fragment> fragmentList = new ArrayList<>();

    public static ZXFragment newInstance( Bundle args) {
        ZXFragment fragment = new ZXFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getContentLayout() {
        return R.layout.zixun_zx_fragment;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        mLineIndicator = (TabIndicator) mContentView.findViewById(R.id.line_indicator);
        mViewpager = (ViewPager) mContentView.findViewById(R.id.viewpager);

        mLineIndicator.setViewPagerSwitchSpeed(mViewpager, 600);
        mLineIndicator.setTabData(mViewpager, Arrays.asList(TYPES), new TabIndicator.TabClickListener() {
            @Override
            public void onClick(int position) {
                //顶部点击的方法公布出来
                mViewpager.setCurrentItem(position);
            }
        });

        fragmentList.add(ZixunFragment.newInstance());
        fragmentList.add(KuaiXunFragment.newInstance());
//        fragmentList.add(SearchFragment.newInstance());
//        fragmentList.add(CoinExchangeFragment.newInstance("bitmex"));
//        fragmentList.add(CoinExchangeFragment.newInstance("huobipro"));
//        fragmentList.add(CoinExchangeFragment.newInstance("cointiger"));
//        fragmentList.add(CoinExchangeFragment.newInstance("okex"));
        mViewpager.setOffscreenPageLimit(3);
        mViewpager.setAdapter(new VPTitleAdapter(getChildFragmentManager(), fragmentList, Arrays.asList(TYPES)));
    }

    @Override
    public void setTitleBar(TitleBarView titleBar) {
        titleBar.setTitleMainText(getResources().getString(R.string.zixun_app_name)).setBackground(getResources().getDrawable(R.drawable.bg_titlebar_jb));
    }
}
